#!/bin/bash
set -e

. _common
## file system
fs="ext3"
dd_count=$normal_size
break_debug=0

#main

ptlfs=$(_ptlname $fs)
mkfs=$(_findmkfs $fs)
echo -e "quiet option test"
echo -e "====================\n"
echo -e "\ncreate raw file $raw\n"
_ptlbreak
[ -f $raw ] && rm $raw
echo -e "    dd if=/dev/zero of=$raw bs=$dd_bs count=$dd_count\n"
dd if=/dev/zero of=$raw bs=$dd_bs count=$dd_count

echo -e "\nformat $raw as $fs raw partition\n"
echo -e "    mkfs.$fs `eval echo "$"mkfs_option_for_$fs""` $raw\n"
_ptlbreak
$mkfs `eval echo "$"mkfs_option_for_$fs""` $raw

echo -e "\nclone $raw to $img\n"
[ -f $img ] && rm $img
echo -e "    $ptlfs -d -c -s $raw -O $img -F -L $logfile\n"
_ptlbreak
time $ptlfs -d -c -s $raw -O $img -F -L $logfile
_check_return_code

echo -e "\nquiet mode\n"
echo -e "    $ptlfs -d -q -c -s $raw -O $img -F -L $logfile\n"
_ptlbreak
time $ptlfs -d -q -c -s $raw -O $img -F -L $logfile
_check_return_code

echo -e "\ndo image checking\n"
echo -e "    $ptlchkimg -s $img -L $logfile\n"
_ptlbreak
$ptlchkimg -s $img -L $logfile
_check_return_code

echo -e "\ncreate raw file $raw for restore\n"
_ptlbreak
[ -f $raw ] && rm $raw
echo -e "    dd if=/dev/zero of=$raw bs=$dd_bs count=$dd_count\n"
dd if=/dev/zero of=$raw bs=$dd_bs count=$dd_count

echo -e "\nrestore $img to $raw\n"
echo -e "    $ptlrestore -s $img -O $raw -C -F -L $logfile\n"
_ptlbreak
$ptlrestore -s $img -O $raw -C -F -L $logfile
_check_return_code

echo -e "\nquiet test ok\n"
echo -e "\nclear tmp files $img $raw $logfile $md5\n"
_ptlbreak
rm -f $img $raw $logfile $md5

